<?php

/**
 * Proveedor filter form base class.
 *
 * @package    aeropostal
 * @subpackage filter
 * @author     Your name here
 */
abstract class BaseProveedorFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'nombre'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'tlf'             => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'direccion'       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'tipo'            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'uMedida'         => new sfWidgetFormPropelChoice(array('model' => 'Unidmedida', 'add_empty' => true)),
      'moneda'          => new sfWidgetFormPropelChoice(array('model' => 'Moneda', 'add_empty' => true)),
      'contacto'        => new sfWidgetFormFilterInput(),
      'tlfContacto'     => new sfWidgetFormFilterInput(),
      'logotipo'        => new sfWidgetFormFilterInput(),
      'preciocomb_list' => new sfWidgetFormPropelChoice(array('model' => 'Estacion', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'nombre'          => new sfValidatorPass(array('required' => false)),
      'tlf'             => new sfValidatorPass(array('required' => false)),
      'direccion'       => new sfValidatorPass(array('required' => false)),
      'tipo'            => new sfValidatorPass(array('required' => false)),
      'uMedida'         => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Unidmedida', 'column' => 'simbolo')),
      'moneda'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Moneda', 'column' => 'id')),
      'contacto'        => new sfValidatorPass(array('required' => false)),
      'tlfContacto'     => new sfValidatorPass(array('required' => false)),
      'logotipo'        => new sfValidatorPass(array('required' => false)),
      'preciocomb_list' => new sfValidatorPropelChoice(array('model' => 'Estacion', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('proveedor_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addPreciocombListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(PreciocombPeer::PROVEEDOR, ProveedorPeer::RIF);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(PreciocombPeer::ESTACION, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(PreciocombPeer::ESTACION, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Proveedor';
  }

  public function getFields()
  {
    return array(
      'rif'             => 'Text',
      'nombre'          => 'Text',
      'tlf'             => 'Text',
      'direccion'       => 'Text',
      'tipo'            => 'Text',
      'uMedida'         => 'ForeignKey',
      'moneda'          => 'ForeignKey',
      'contacto'        => 'Text',
      'tlfContacto'     => 'Text',
      'logotipo'        => 'Text',
      'preciocomb_list' => 'ManyKey',
    );
  }
}
